<template>
	<view class="container">

		<uni-section title="开关" type="line">
			<uni-group>
				<view>
					<uni-icons custom-prefix="iconfont" type="icon-kgkaiguan_o" :style="{color: color}" size="30"
						@click="kaiguan()"></uni-icons>
				</view>
			</uni-group>
		</uni-section>


	</view>
</template>


<script>
	import store from '@/store/index.js'; //需要引入store
	import {
		rejects
	} from 'assert';
	import {
		resolve
	} from 'url';

	export default {
		data() {
			return {
				color: '',
				kg:''
			}
		},
		methods: {
			kaiguan() {
				console.log('kaiguan')
				if(this.color==="black"){
					this.kg={"kg":"1"}
				}else{
					this.kg={"kg":"0"}
				}

				const response =  this.$api.CreateCommand(this.kg)
				response.then((data) =>{
				console.log( data.data)
				if(this.color==="black"){
					this.color="green"
				}else if(this.color==="green"){
					this.color="black"
					
				}
				
				
				
			})
			},
			ListProperties() {
				console.log("ListProperties")


				const response = this.$api.ListProperties();
				console.log(response)
				
				console.log(response.statusCode)
				response.then(function(res) {
					console.log("res.data");

					console.log(res.data);

				})
				console.log("this.color")
				

			}
		},
		mounted() {
			console.log("mounted")
			this.$api.ListProperties().then((data) =>{
				console.log( data.data)
				if(data.data==0){
					this.color="black"
				}else if(data.data==1){
					this.color="green"
					
				}
				
				
				
			})
		},
		updated() {
			console.log("updated")


			// Vue组件更新后执行的代码
		},
		onload() {
			console.log("onload")
		}

	};
</script>